package dto

import (
	"strconv"
	"strings"
	"time"
	"vrcm/src/vrcm/app/admin/models/monitor"
	"vrcm/src/vrcm/common/dto"
	common "vrcm/src/vrcm/common/models"
)

type MonitorBasicGetPageReq struct {
	dto.Pagination `search:"-"`
	TenantId       string `json:"tenant_id"  search:"type:exact;column:tenant_id;table:monitor_basic"`
	CreateTime     int64  `json:"create_time"  search:"type:order;column:create_time;table:monitor_basic"`
	BindId         string `json:"bind_id"  search:"-"`
}

type MonitorBasicOrder struct {
	Id           string `form:"idOrder"  search:"type:order;column:id;table:monitor_basic"`
	TenantId     string `form:"tenantIdOrder"  search:"type:order;column:tenant_id;table:monitor_basic"`
	MonitorName  string `form:"monitorNameOrder"  search:"type:order;column:monitor_name;table:monitor_basic"`
	TemplateType string `form:"templateTypeOrder"  search:"type:order;column:template_type;table:monitor_basic"`
	MonitorState string `form:"monitorStateOrder"  search:"type:order;column:monitor_state;table:monitor_basic"`
	BackPadding  string `form:"backPaddingOrder"  search:"type:order;column:back_padding;table:monitor_basic"`
	VideoPadding string `form:"videoPaddingOrder"  search:"type:order;column:video_padding;table:monitor_basic"`
	TaskId       string `form:"taskIdOrder"  search:"type:order;column:task_id;table:monitor_basic"`
	MonitorUrl   string `form:"monitorUrlOrder"  search:"type:order;column:monitor_url;table:monitor_basic"`
	IsShouwName  string `form:"isShouwNameOrder"  search:"type:order;column:is_shouw_name;table:monitor_basic"`
	IsShowData   string `form:"isShowDataOrder"  search:"type:order;column:is_show_data;table:monitor_basic"`
	IsShowVolume string `form:"isShowVolumeOrder"  search:"type:order;column:is_show_volume;table:monitor_basic"`
	CreateTime   string `form:"createTimeOrder"  search:"type:order;column:create_time;table:monitor_basic"`
	UpdateTime   string `form:"updateTimeOrder"  search:"type:order;column:update_time;table:monitor_basic"`
	CreateBy     string `form:"createByOrder"  search:"type:order;column:create_by;table:monitor_basic"`
	UpdateBy     string `form:"updateByOrder"  search:"type:order;column:update_by;table:monitor_basic"`
}

func (m *MonitorBasicGetPageReq) GetNeedSearch() interface{} {
	return *m
}

type MonitorBasicInsertReq struct {
	Id           int    `json:"-" comment:""` //
	TenantId     string `json:"tenant_id" comment:"租户"`
	BindId       string `json:"bind_id" comment:"关联id"`
	MonitorName  string `json:"monitor_name" comment:"监看名称"`
	TemplateType int    `json:"template_type" comment:"模版 1双视窗 2四宫格 3九宫格 4十六宫格 5 4PGM 6  6PGM 7 7PGM"`
	//MonitorState int    `json:"monitor_state" comment:"监看状态 1 启用 2停用"`
	BackPadding  string `json:"back_padding" comment:"背景图片"`
	VideoPadding string `json:"video_padding" comment:"视频垫图"`
	//TaskId       string `json:"task_id" comment:"任务id"`
	//MonitorUrl   string `json:"monitorUrl" comment:"监看地址"`
	IsShowName   int `json:"is_show_name" comment:"是否显示机位名称"`
	IsShowData   int `json:"is_show_data" comment:"是否显示关键数据"`
	IsShowVolume int `json:"is_show_volume" comment:"是否显示音量"`
	common.ControlBy
}

func (s *MonitorBasicInsertReq) Generate(model *monitor.MonitorBasic) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	now := time.Now().Unix()
	model.TenantId = s.TenantId
	model.MonitorName = s.MonitorName
	model.TemplateType = s.TemplateType
	model.MonitorState = 0
	model.BackPadding = s.BackPadding
	model.VideoPadding = s.VideoPadding
	//model.TaskId = s.TaskId
	//model.MonitorUrl = s.MonitorUrl
	model.IsShowName = s.IsShowName
	model.IsShowData = s.IsShowData
	model.IsShowVolume = s.IsShowVolume
	model.BindId = s.BindId
	model.CreateTime = now
	model.UpdateTime = now
	model.CreateBy = s.CreateBy // 添加这而，需要记录是被谁创建的
}

func (s *MonitorBasicInsertReq) GetId() interface{} {
	return s.Id
}

type MonitorBasicUpdateReq struct {
	MonitorBasic MonitorBasic            `json:"basic" comment:"basic"`
	Configs      []monitor.MonitorConfig `json:"configs" comment:"configs"`
	BindId       string                  `json:"bind_id" comment:""`
}
type MonitorBasic struct {
	Id           int      `json:"id" comment:""` //
	TenantId     string   `json:"tenant_id" comment:"租户" validate:"required"`
	MonitorName  string   `json:"monitor_name" comment:"监看名称"`
	TemplateType int      `json:"template_type" comment:"模版 1双视窗 2四宫格 3九宫格 4十六宫格 5 4PGM 6  6PGM 7 7PGM"`
	BackPadding  string   `json:"back_padding" comment:"背景图片"`
	VideoPadding string   `json:"video_padding" comment:"视频垫图"`
	IsShowName   int      `json:"is_show_name" comment:"是否显示机位名称"`
	IsShowData   int      `json:"is_show_data" comment:"是否显示关键数据"`
	IsShowVolume int      `json:"is_show_volume" comment:"是否显示音量"`
	Equips       []string `json:"equips" comment:"适配设备"`
	Worksites    []int    `json:"worksites" comment:"适配设备"`
	common.ControlBy
}

type MonitorBasicConfigReq struct {
	Id         int    `json:"id" comment:""` //
	BasicId    int64  `json:"basic_id" comment:"监看任务id"`
	TenantId   string `json:"tenant_id" comment:"租户"`
	ViewNo     int    `json:"view_no" comment:"机位号"`
	ViewName   string `json:"view_name" comment:"机位名称"`
	InputMode  int    `json:"input_mode" comment:"输入模式 1 常用信源 2自定义网络流 3调度任务"`
	SourceType int    `json:"source_type" comment:"信源类型 1我的信源 分享信源"`
	StreamType int    `json:"stream_type" comment:"流类型 1原始流 2转码流"`
	SourceId   int64  `json:"source_id" comment:"信源id"`
	ActiveItem int    `json:"active_item" comment:"监看流 1主 2备 3 辅 5自动"`
	StreamUrl  string `json:"stream_url" comment:"流地址"`
	common.ControlBy
	common.ModelTime
}

func (s *MonitorBasicUpdateReq) Generate(model *monitor.MonitorBasic) {
	if s.MonitorBasic.Id == 0 {
		model.Model = common.Model{Id: s.MonitorBasic.Id}
	}
	now := time.Now().Unix()
	model.TenantId = s.MonitorBasic.TenantId
	model.TemplateType = s.MonitorBasic.TemplateType
	model.BackPadding = s.MonitorBasic.BackPadding
	model.MonitorName = s.MonitorBasic.MonitorName
	model.VideoPadding = s.MonitorBasic.VideoPadding
	model.IsShowName = s.MonitorBasic.IsShowName
	model.IsShowData = s.MonitorBasic.IsShowData
	model.IsShowVolume = s.MonitorBasic.IsShowVolume
	model.UpdateTime = time.Now().Unix()
	model.UpdateBy = s.MonitorBasic.UpdateBy // 添加这而，需要记录是被谁更新的
	if s.MonitorBasic.Id <= 0 {
		model.MonitorState = 2
		model.CreateTime = now
	}
	model.BindId = s.BindId
	model.UpdateTime = now
	equips := strings.Join(s.MonitorBasic.Equips, ",")
	model.Equips = equips
	worksiteArr := make([]string, 0, 5)
	for _, worksiteId := range s.MonitorBasic.Worksites {
		w := strconv.Itoa(worksiteId)
		worksiteArr = append(worksiteArr, w)
	}
	worksites := strings.Join(worksiteArr, ",")
	model.Worksites = worksites

}

func (s *MonitorBasicUpdateReq) GetId() interface{} {
	return s.MonitorBasic.Id
}

// MonitorBasicGetReq 功能获取请求参数
type MonitorBasicGetReq struct {
	Id int `uri:"id"`
}

type MonitorConfigGetReq struct {
	Id int `uri:"id"`
}

func (s *MonitorBasicGetReq) GetId() interface{} {
	return s.Id
}

// MonitorBasicDeleteReq 功能删除请求参数
type MonitorBasicDeleteReq struct {
	Ids []int `json:"ids"`
}

type StartMonitorEventReq struct {
	Id int `json:"id"`
}

type StopMonitorEventReq struct {
	Id int `json:"id"`
}

type EventMonitorDeleteReq struct {
	Id int `json:"id"`
}

func (s *MonitorBasicDeleteReq) GetId() interface{} {
	return s.Ids
}

type MonitorStartReq struct {
	EventId  string `json:"event_id"`
	TenantId string `json:"tenant_id" comment:"租户"`
}

type MonitorStopReq struct {
	EventId  string `json:"event_id"`
	TenantId string `json:"tenant_id" comment:"租户"`
}

type CreateShareReq struct {
	Id         int    `json:"id" comment:""` //
	TenantId   string `json:"tenant_id" comment:"租户"`
	IsPassword int    `json:"is_password" comment:"是否启用密码 1是 2否"`
	ExpireTime int64  `json:"expire_time" comment:"过期时间  -1为永久 单位天"`
}

type GetShareInfoReq struct {
	Uuid     string `json:"uuid" comment:""` //
	Password string `json:"password" comment:"密码"`
}

type RestReq struct {
	Id int `json:"id" comment:""` //
}

type MonitorBasicGetByEventIdReq struct {
	EventId string `json:"event_id"`
}

type StartMonitorReq struct {
	Id int `json:"id"`
}

type StopMonitorReq struct {
	Id int `json:"id"`
}

type DeleteMonitorReq struct {
	Id int `json:"id"`
}

type EnableMonitorReq struct {
	Id           int `json:"id"`
	MonitorState int `json:"monitor_state"`
}

type GetMemberByCodeReq struct {
	TenantId string `json:"tenant_id" comment:"租户"`
	Code     int    `json:"code"`
}

type CopyMonitorEventReq struct {
	Id        int    `json:"id"`
	EventName string `json:"event_name" comment:"活动名"`
}
